package com.demo.javaee.ref_type;

import cn.hutool.core.map.WeakConcurrentMap;
import org.junit.jupiter.api.Test;

import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;

/**
 * @author shenguangyang
 */
public class WeakReferenceDemo {
    public static class TestData {
        @Override
        protected void finalize() throws Throwable {
            System.out.println("----------------finalize");
        }
    }

    @Test
    public void test1() throws InterruptedException {
        WeakReference<TestData> wf = new WeakReference<>(new TestData());
        System.out.println(wf.get());
        System.gc();
        TimeUnit.SECONDS.sleep(1);
        System.out.println(wf.get());
    }

    @Test
    public void test2() throws InterruptedException {
        WeakConcurrentMap<String, TestData> wf = new WeakConcurrentMap<>();
//        System.out.println(wf.get());
//        System.gc();
//        TimeUnit.SECONDS.sleep(1);
//        System.out.println(wf.get());
    }
}
